﻿using SuperMap.Data;
using SuperMap.Realspace;
using System;
using System.Collections.Generic;
using WeifenLuo.WinFormsUI.Docking;
using Ycjw.PipeLine.Map.Basic.Conditions;
using Ycjw.PipeLine.Map.Basic.SuperMap;

namespace Ycjw.PipeLine.Map.Tools.Conditions
{
    public class CZSearcher : ConditionPanel
    {
        private Sunny.UI.UIGroupBox uiGroupBoxcxlx;
        private Sunny.UI.UIGroupBox uiGroupBoxcxcxcs;
        private Sunny.UI.UILabel uiLabel1;
        private Sunny.UI.UIComboBox uiComboBoxgxxz;
        private LayerWithDataListPanel LayerWithDataListPanel;
        public CZSearcher() : base()
        {
            InitializeComponent();
        }

        protected override void OnLoad(EventArgs e)
        {
            LayerWithDataListPanel = new LayerWithDataListPanel()
            {
                Dock = System.Windows.Forms.DockStyle.Fill
            };
            Scene scene = this.Scene;
            if (scene == null) return;
            LayerWithDataListPanel.Init(scene);
            //LayerWithDataListPanel.LoadToVector();   
            var types = new List<DatasetType>()
            {
                DatasetType.Line,
                DatasetType.Line3D,
                DatasetType.Network,
                DatasetType.Network3D
            };
            LayerWithDataListPanel.LoadTo(types);
            this.uiGroupBoxcxlx.Controls.Add(LayerWithDataListPanel);
            uiGroupBoxcxlx.Width = this.Width / 2;
        }

        public override object Do(DockPanel dockPanel = null)
        {
            var dataset = LayerWithDataListPanel.SelectLayer3DDataset;
            if (dataset == null)
            {
                Sunny.UI.UIMessageTip.ShowError("选择的图层不是矢量图层");
                return null;
            }
            var dataSetVector = dataset.Dataset as SuperMap.Data.DatasetVector;
            bool hasGJField = false;

            for (int i = 0; i < dataSetVector.FieldInfos.Count; i++)
            {
                if (dataSetVector.FieldInfos[i].Name == "材质")
                {
                    hasGJField = true;
                    break;
                }
            }

            if (!hasGJField)
            {
                Sunny.UI.UIMessageTip.ShowError("选择的图层没有材质信息");
                return null;
            }
            DatasetVectorEx dvEx = new DatasetVectorEx(dataset.Name)
            {
                DatasetVector = dataSetVector
            };

            return dvEx.Query("材质 = '" + this.uiComboBoxgxxz.Text + "'");
        }




        private void InitializeComponent()
        {
            this.uiGroupBoxcxlx = new Sunny.UI.UIGroupBox();
            this.uiGroupBoxcxcxcs = new Sunny.UI.UIGroupBox();
            this.uiLabel1 = new Sunny.UI.UILabel();
            this.uiComboBoxgxxz = new Sunny.UI.UIComboBox();
            this.uiGroupBoxcxcxcs.SuspendLayout();
            this.SuspendLayout();
            // 
            // uiGroupBoxcxlx
            // 
            this.uiGroupBoxcxlx.Dock = System.Windows.Forms.DockStyle.Left;
            this.uiGroupBoxcxlx.Font = new System.Drawing.Font("微软雅黑", 12F);
            this.uiGroupBoxcxlx.Location = new System.Drawing.Point(0, 0);
            this.uiGroupBoxcxlx.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
            this.uiGroupBoxcxlx.MinimumSize = new System.Drawing.Size(1, 1);
            this.uiGroupBoxcxlx.Name = "uiGroupBoxcxlx";
            this.uiGroupBoxcxlx.Padding = new System.Windows.Forms.Padding(0, 32, 0, 0);
            this.uiGroupBoxcxlx.Size = new System.Drawing.Size(215, 311);
            this.uiGroupBoxcxlx.TabIndex = 0;
            this.uiGroupBoxcxlx.Text = "查询类型";
            // 
            // uiGroupBoxcxcxcs
            // 
            this.uiGroupBoxcxcxcs.Controls.Add(this.uiLabel1);
            this.uiGroupBoxcxcxcs.Controls.Add(this.uiComboBoxgxxz);
            this.uiGroupBoxcxcxcs.Dock = System.Windows.Forms.DockStyle.Fill;
            this.uiGroupBoxcxcxcs.Font = new System.Drawing.Font("微软雅黑", 12F);
            this.uiGroupBoxcxcxcs.Location = new System.Drawing.Point(215, 0);
            this.uiGroupBoxcxcxcs.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
            this.uiGroupBoxcxcxcs.MinimumSize = new System.Drawing.Size(1, 1);
            this.uiGroupBoxcxcxcs.Name = "uiGroupBoxcxcxcs";
            this.uiGroupBoxcxcxcs.Padding = new System.Windows.Forms.Padding(0, 32, 0, 0);
            this.uiGroupBoxcxcxcs.Size = new System.Drawing.Size(228, 311);
            this.uiGroupBoxcxcxcs.TabIndex = 1;
            this.uiGroupBoxcxcxcs.Text = "查询参数";
            // 
            // uiLabel1
            // 
            this.uiLabel1.Font = new System.Drawing.Font("微软雅黑", 12F);
            this.uiLabel1.Location = new System.Drawing.Point(7, 32);
            this.uiLabel1.Name = "uiLabel1";
            this.uiLabel1.Size = new System.Drawing.Size(100, 23);
            this.uiLabel1.TabIndex = 1;
            this.uiLabel1.Text = "管线性质：";
            this.uiLabel1.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
            // 
            // uiComboBoxgxxz
            // 
            this.uiComboBoxgxxz.DropDownStyle = Sunny.UI.UIDropDownStyle.DropDownList;
            this.uiComboBoxgxxz.FillColor = System.Drawing.Color.White;
            this.uiComboBoxgxxz.Font = new System.Drawing.Font("微软雅黑", 12F);
            this.uiComboBoxgxxz.Items.AddRange(new object[] {
            "塑料",
            "铁",
            "铜",
            "钢",
            "铝合金"});
            this.uiComboBoxgxxz.Location = new System.Drawing.Point(8, 60);
            this.uiComboBoxgxxz.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
            this.uiComboBoxgxxz.MinimumSize = new System.Drawing.Size(63, 0);
            this.uiComboBoxgxxz.Name = "uiComboBoxgxxz";
            this.uiComboBoxgxxz.Padding = new System.Windows.Forms.Padding(0, 0, 30, 2);
            this.uiComboBoxgxxz.Size = new System.Drawing.Size(175, 29);
            this.uiComboBoxgxxz.TabIndex = 0;
            this.uiComboBoxgxxz.Text = "塑料";
            this.uiComboBoxgxxz.TextAlignment = System.Drawing.ContentAlignment.MiddleLeft;
            // 
            // CZSearcher
            // 
            this.Controls.Add(this.uiGroupBoxcxcxcs);
            this.Controls.Add(this.uiGroupBoxcxlx);
            this.Name = "CZSearcher";
            this.Size = new System.Drawing.Size(443, 311);
            this.uiGroupBoxcxcxcs.ResumeLayout(false);
            this.ResumeLayout(false);

        }


    }
}
